package cn.dgut.FrontManger;

import cn.dgut.Utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/SignCourse")
public class SignCourseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int exsit = 0;
        String sid = request.getParameter("sid");
        String cid = request.getParameter("cid");

        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String time = dateFormat.format(date);

        String sql = "INSERT INTO `Select_Course` VALUES (null,"+cid+","+sid+", '"+time+"');";
        exsit = new JDBCUtils().querySQL(sql);

        response.setContentType("application/json,charset=utf-8");
        String strJson = "{\"exsit\":\""+exsit+"\"}";
        response.getWriter().println(strJson);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}